#include <list>
#include <iostream>
class Fancy
{
private:
    std::list<int> data;
    int mol = 1000000007;

public:
    Fancy()
    {
    }

    void append(int val)
    {
        data.push_back(val);
    }

    void addAll(int inc)
    {
        for (std::list<int>::iterator i = data.begin(); i != data.end(); i++)
        {
            long long temp = *i;
            temp += inc;
            if (temp >= mol)
            {
                temp -= mol;
            }
            *i = temp;
        }
    }

    void multAll(int m)
    {
        for (std::list<int>::iterator i = data.begin(); i != data.end(); i++)
        {
            long long temp = *i;
            temp *= m;
            if (temp >= mol)
            {
                temp %= mol;
            }
            *i = temp;
        }
    }

    int getIndex(int idx)
    {
        if (idx < 0 || idx >= data.size())
        {
            return -1;
        }
        std::list<int>::iterator i = data.begin();
        for (int j = 0; j < idx; j++)
        {
            i++;
        }
        return *i;
    }
};

int main(int argc, char const *argv[])
{
    Fancy fancy;
    fancy.append(2);                             // 奇妙序列：[2]
    fancy.addAll(3);                             // 奇妙序列：[2+3] -> [5]
    fancy.append(7);                             // 奇妙序列：[5, 7]
    fancy.multAll(2);                            // 奇妙序列：[5*2, 7*2] -> [10, 14]
    std::cout << fancy.getIndex(0) << std::endl; // 返回 10
    fancy.addAll(3);                             // 奇妙序列：[10+3, 14+3] -> [13, 17]
    fancy.append(10);                            // 奇妙序列：[13, 17, 10]
    fancy.multAll(2);                            // 奇妙序列：[13*2, 17*2, 10*2] -> [26, 34, 20]
    std::cout << fancy.getIndex(0) << std::endl; // 返回 26
    std::cout << fancy.getIndex(1) << std::endl; // 返回 34
    std::cout << fancy.getIndex(2) << std::endl; // 返回 20

    return 0;
}

/**
 * Your Fancy object will be instantiated and called as such:
 * Fancy* obj = new Fancy();
 * obj->append(val);
 * obj->addAll(inc);
 * obj->multAll(m);
 * int param_4 = obj->getIndex(idx);
 */